#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=20;
typedef long long LL;
const int MOD=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Node{
    LL cnt,sum,square_sum;
    Node(LL _cnt=0,LL _sum=0,LL _square_sum=0)
    :cnt(_cnt),
    sum(_sum),
    square_sum(_square_sum)
    { }
    void add(const LL y,const Node& tmp){
        cnt=(cnt+tmp.cnt)%MOD;
        sum=(sum+tmp.sum+tmp.cnt*y%MOD)%MOD;
        square_sum=(square_sum+tmp.cnt*y%MOD*y%MOD)%MOD;
        square_sum=(square_sum+2*y%MOD*tmp.sum+tmp.square_sum)%MOD;
    }
}dp[maxn][10][10];
LL a[maxn],pw[maxn],tot=0;
void init(){
     pw[0]=1;
     for(LL i=1;i<maxn;i++) pw[i]=pw[i-1]*10%MOD;
}
Node dfs(LL pos,LL st1,LL st2,bool lead,bool limit){
   if(pos==0){
      return Node(st1&&st2,0,0);
   }
   if(!limit&&(dp[pos][st1][st2].cnt>0)) return dp[pos][st1][st2];
   Node ans;ans.cnt=0;
   LL bound=(limit?a[pos]:9);
   for(LL d=0;d<=bound;d++){
       if(d==7) continue;
       if(lead&&d==0){
            Node tmp=dfs(pos-1,0,0,1,d==bound&&limit);
            ans.add(d*pw[pos-1]%MOD,tmp);
       }
       else if(lead&&(d!=0)){
            Node tmp=dfs(pos-1,(st1+d)%7,(st2*10+d)%7,0,d==bound&&limit);
            ans.add(d*pw[pos-1]%MOD,tmp);
       }
       else{
            Node tmp=dfs(pos-1,(st1+d)%7,(st2*10+d)%7,0,d==bound&&limit);
            ans.add(d*pw[pos-1]%MOD,tmp);
       }
   }
   if(!limit) dp[pos][st1][st2]=ans;
   return ans;
}
LL solve(LL x){
    tot=0;memset(a,0,sizeof(a));
    while(x){
        a[++tot]=x%10;x/=10;
    }
    return dfs(tot,0,0,1,1).square_sum%MOD;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    init();
    LL t;cin>>t;
    while(t--){
        LL l,r;cin>>l>>r;
        cout<<(solve(r)-solve(l-1)+MOD)%MOD<<endl;
    }
   	return 0;
}
